<?php

/**
 * This is the model class for table "project_profile".
 *
 * The followings are the available columns in table 'project_profile':
 * @property string $id
 * @property string $project_id
 * @property string $parent_project
 * @property string $name
 * @property integer $hierarchal_type
 * @property string $about
 * @property string $requirement
 * @property integer $status
 * @property string $supervisor_id
 * @property string $vote
 * @property double $rate
 * @property string $logo
 * @property string $create_time
 * @property string $last_update
 * @property string $author_id
 *
 * The followings are the available model relations:
 * @property Project $project
 * @property User $supervisor
 * @property User $author
 * @property ProjectProfileComment[] $projectProfileComments
 */
class ProjectProfile extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return ProjectProfile the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'project_profile';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('project_id, parent_project, name, hierarchal_type, about, requirement, status, supervisor_id, vote, rate, logo, create_time, last_update, author_id', 'required'),
			array('hierarchal_type, status', 'numerical', 'integerOnly'=>true),
			array('rate', 'numerical'),
			array('project_id, parent_project, supervisor_id, vote, author_id', 'length', 'max'=>10),
			array('name', 'length', 'max'=>40),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, project_id, parent_project, name, hierarchal_type, about, requirement, status, supervisor_id, vote, rate, logo, create_time, last_update, author_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'project' => array(self::BELONGS_TO, 'Project', 'project_id'),
			'supervisor' => array(self::BELONGS_TO, 'User', 'supervisor_id'),
			'author' => array(self::BELONGS_TO, 'User', 'author_id'),
			'projectProfileComments' => array(self::HAS_MANY, 'ProjectProfileComment', 'project_profile_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'project_id' => 'Project',
			'parent_project' => 'Parent Project',
			'name' => 'Name',
			'hierarchal_type' => 'Hierarchal Type',
			'about' => 'About',
			'requirement' => 'Requirement',
			'status' => 'Status',
			'supervisor_id' => 'Supervisor',
			'vote' => 'Vote',
			'rate' => 'Rate',
			'logo' => 'Logo',
			'create_time' => 'Create Time',
			'last_update' => 'Last Update',
			'author_id' => 'Author',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('project_id',$this->project_id,true);
		$criteria->compare('parent_project',$this->parent_project,true);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('hierarchal_type',$this->hierarchal_type);
		$criteria->compare('about',$this->about,true);
		$criteria->compare('requirement',$this->requirement,true);
		$criteria->compare('status',$this->status);
		$criteria->compare('supervisor_id',$this->supervisor_id,true);
		$criteria->compare('vote',$this->vote,true);
		$criteria->compare('rate',$this->rate);
		$criteria->compare('logo',$this->logo,true);
		$criteria->compare('create_time',$this->create_time,true);
		$criteria->compare('last_update',$this->last_update,true);
		$criteria->compare('author_id',$this->author_id,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}